using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Lexalytics;

namespace SalienceEngineDemo
{
    public partial class ctrlGetSentimentTaggedText : UserControl, DemoControl
    {
        public RichTextBox oTextBox;
        private HighlightManager oHighlighting;

        public ctrlGetSentimentTaggedText(RichTextBox oTextBox)
        {
            InitializeComponent();
            oHighlighting = new HighlightManager();
            defineHighlightColors();
            oHighlighting.CreateLegend(legendPanel);
            this.oTextBox = oTextBox;
            EnableProcessButton();
        }

        private void defineHighlightColors()
        {
            oHighlighting.AddHighlight("Positive", "#00FF00"); //Green
            oHighlighting.AddHighlight("HSD_Positive", "#00B800"); //Green
            oHighlighting.AddHighlight("Neutral", "#00FFFF"); //Aqua
            oHighlighting.AddHighlight("HSD_Neutral", "#0AAAAA"); //Aqua
            oHighlighting.AddHighlight("Negative", "#FF2201"); //Red
            oHighlighting.AddHighlight("HSD_Negative", "#AA332C"); //Red
            oHighlighting.AddHighlight("Inverted", "#FF00FF"); //Fuscia
            oHighlighting.AddHighlight("Stop", "#000000", "#FFFFFF"); //Black
            oHighlighting.AddHighlight("Possible", "#000000", "#CCCCCC");
            oHighlighting.AddHighlight("Sentence_Polar","#0000FF","#FFFFFF");

            oHighlighting.AddSynonym("INTERNAL_POSITIVE", "Positive");
            oHighlighting.AddSynonym("INTERNAL_NEGATIVE", "Negative");
            oHighlighting.AddSynonym("INTERNAL_NEUTRAL", "Neutral");

            oHighlighting.AddSynonym("HANDSCORE_POSITIVE", "HSD_Positive");
            oHighlighting.AddSynonym("HANDSCORE_NEGATIVE", "HSD_Negative");
            oHighlighting.AddSynonym("HANDSCORE_NEUTRAL", "HSD_Neutral");

            oHighlighting.AddSynonym("INVERT", "Inverted");

            oHighlighting.AddSynonym("STOP", "Stop"); //Black
            oHighlighting.AddSynonym("POSSIBLE", "Possible");

            oHighlighting.AddSynonym("SENTENCE_POLAR","Sentence_Polar");
        }

        private void getPOSTaggedText_VisibleChanged(object sender, EventArgs e)
        {
            webResults.DocumentText = "";
        }

        public void processText()
        {
            try
            {
                SalienceDemo.oSalienceSession.PrepareText(this.oTextBox.Text);
                webResults.DocumentText = oHighlighting.FormatResults(SalienceDemo.oSalienceSession.GetSentimentTaggedText());
            }
            catch (SalienceException e)
            {
                MessageBox.Show(e.Message, "Salience Demo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btnProcess_Click(object sender, EventArgs e)
        {
            processText();
        }

        #region DemoControl interface methods
        public void btnOptions_Click(object sender, EventArgs e)
        {
            ((SalienceDemo)this.Parent).StartOptionsDialog((int)Dialogs.Options.OptionSections.NOTHING);
            EnableProcessButton();
        }

        public void SetFontSize()
        {
            if (this.webResults.Document.Body != null)
            {
                Graphics g = this.CreateGraphics();
                float pixels = Properties.Settings.Default.fFontSize * g.DpiX / 72;
                g.Dispose();
                this.webResults.Document.Body.Style = "font-size:" + pixels + "px;";
            }
        }

        public void EnableProcessButton()
        {
            this.btnProcess.Enabled = (oTextBox.Text.Trim().Length > 0);
        }

        #endregion
    }
}
